package eleventh.StringBuffer类;

public class 替换指定范围内容 {
    public static void main(String[] args) {
        StringBuffer sb = new StringBuffer();
        sb.append("一去二三里");
        System.out.println(sb);
        sb.replace(0,2,"AA");   //替换位置 start-(end-1)
        System.out.println(sb);
        System.out.println();
        //StringBuffer用的是replace() String类用的是replaceAll()
        String str="一去二三里";
        System.out.println(str);
        str=str.replace(str,"烟村四五家");
        System.out.println(str);

    }
}
/*
D:\WorkSpaces\Java\jdk-21\bin\java.exe "-javaagent:D:\Software\IntelliJ IDEA\IntelliJ IDEA 2023.3.2\lib\idea_rt.jar=52634:D:\Software\IntelliJ IDEA\IntelliJ IDEA 2023.3.2\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath D:\WorkSpaces\JavaDevelopBase_start_329\out\production\JavaDevelopBase_start_329 eleventh.StringBuffer类.替换指定范围内容
一去二三里
AA二三里

一去二三里
烟村四五家

Process finished with exit code 0
 */